//
//  BGMCommontView.m
//  BGM
//
//  Created by 我要变好看 on 2018/12/17.
//  Copyright © 2018 com.alirtc.demo. All rights reserved.
//

#import "BGMShareView.h"
#import "Common.h"


@implementation BGMShareButton

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self != nil) {
        self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width/2, frame.size.width/2)];
        [self addSubview:self.imageView];
        self.imageView.center = CGPointMake(frame.size.width/2, 30);

        self.textLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,60, frame.size.width, 20)];
        self.textLabel.textAlignment = NSTextAlignmentCenter;
        self.textLabel.textColor = bgmsmallColor;
        self.textLabel.font = [UIFont systemFontOfSize:12];
        [self addSubview:self.textLabel];
    }
    return self;
}

@end





@interface BGMShareView ()

@property (nonatomic, strong)NSMutableArray *btnArray;
@property (nonatomic, strong)NSMutableArray *PublicArray;

@property (nonatomic, strong)UIImageView *shareImage;


@end

@implementation BGMShareView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self != nil) {
        self.backgroundColor = [UIColor clearColor];
        UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        bgView.backgroundColor =[UIColor blackColor];;
        bgView.alpha = 0.6;
        [self addSubview:bgView];
        UITapGestureRecognizer *tag = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickBg)];
        [self addGestureRecognizer:tag];
        
        
        self.shareImage= [[UIImageView alloc]initWithFrame:CGRectMake(30, frame.size.height-350,  frame.size.width-60, 150)];
        [self.shareImage setImage:[UIImage imageNamed:@"shareHeard"]];
        [self addSubview:self.shareImage];
        self.shareImage.hidden = YES;
        
        
        UIView *shareView = [[UIView alloc]initWithFrame:CGRectMake(0, frame.size.height-200+10, frame.size.width, 250)];
        shareView.backgroundColor = [UIColor whiteColor];
        shareView.layer.cornerRadius = 30;
        shareView.layer.masksToBounds = YES;
        [self addSubview:shareView];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, 100, 40)];
        label.text = @"     帮转到";
        label.textColor = bgmgrayColor;
        label.font = [UIFont systemFontOfSize:15];
        [shareView addSubview:label];
        
        
        self.btnArray = [[NSMutableArray alloc]init];
        self.PublicArray = [[NSMutableArray alloc]init];

        float w = 100;
        float spx = (SCREENW-w*4)/5;
        NSArray *array = @[@"我的人脉",@"通讯录",@"微信朋友圈",@"微博"];
        for (int i =0 ; i<4; i++) {
            BGMShareButton *btn = [[BGMShareButton alloc]initWithFrame:CGRectMake((spx*(i+1))+(w*i), 45, w, 90)];
            [btn.imageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"share_%d",i]]];
            btn.textLabel.text = [array objectAtIndex:i];
            [shareView addSubview:btn];
            btn.tag = 100+i;
            [self.btnArray addObject:btn];
            if (i >0 ) {
                [self.PublicArray addObject:btn];
            }
            
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickShare:)];
            [btn addGestureRecognizer:tap];
        }
        
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 140, frame.size.width, 0.3)];
        line.backgroundColor = [UIColor grayColor];
        line.alpha = 0.3;
        [shareView addSubview:line];
        
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 140, SCREENW, 40)];
        [btn setTitle:@"取消" forState:UIControlStateNormal];
        btn.backgroundColor = [UIColor clearColor];
        [btn setTitleColor:bgmgrayColor forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:17];
        [shareView addSubview:btn];
        
        [btn addTarget:self action:@selector(clickCancel) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}
- (void)clickBg{
    [self.shareDelegate clickCancel];
}
- (void)clickShare:(UIGestureRecognizer *)gestureView{
    UIView *shareView = gestureView.view;
    int type = (int)shareView.tag;
    [self.shareDelegate clickShare:type];
    
}
- (void)clickCancel{
    [self.shareDelegate clickCancel];
}
- (void)msgType:(BOOL)isPublicMsg{
    float w = 100;
    if (isPublicMsg) {
        BGMShareButton *btn = [self viewWithTag:100];
        btn.hidden = YES;
        
        self.shareImage.hidden = NO;
        float spx = (SCREENW-w*3)/4;
        for (int i =0 ; i<self.PublicArray.count; i++) {
            BGMShareButton *btn = [self.PublicArray objectAtIndex:i];
            btn.frame = CGRectMake((spx*(i+1))+(w*i), 45, w, 90);
        }
    }else{
        BGMShareButton *btn = [self viewWithTag:100];
        btn.hidden = NO;
        self.shareImage.hidden = YES;
        float spx = (SCREENW-w*4)/5;
        for (int i =0 ; i<self.btnArray.count; i++) {
            BGMShareButton *btn = [self.btnArray objectAtIndex:i];
            btn.frame = CGRectMake((spx*(i+1))+(w*i), 45, w, 90);
        }
    }
}
@end
